package com.weather;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;

/**
 * Activitate in care se adauga un oras
 *
 */

public class AddCity extends Activity {
	
	EditText city;
	Button ok, cancel;

	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addcity);        

    	city = (EditText) findViewById(R.id.city);
    	city.setOnKeyListener(new OnKeyListener() {
		    public boolean onKey(View v, int keyCode, KeyEvent event) {
		    	
		        if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {        
		          return true;
		        }
		        return false;
		    }
		});
    	
    	ok = (Button) findViewById(R.id.ok);
    	ok.setOnClickListener(new OnClickListener() {
		    public void onClick(View v) {
		    	Intent answer = new Intent();
		    	if(!city.getText().toString().equals("")) {
		    		answer.putExtra("city", city.getText().toString());
		    		setResult(1, answer);
		    		finish();
		    	} 
		    	
		    }
		});
    	
    	cancel = (Button) findViewById(R.id.cancel);
    	cancel.setOnClickListener(new OnClickListener() {
		    public void onClick(View v) {
		    	Intent answer = new Intent();
		    	setResult(0, answer);
		    	finish();
		    }
		});
	}
	
}
